package com.bing.jh.controller;

import cn.hutool.core.text.CharSequenceUtil;
import com.bing.bingPro.common.BaseResult;
import com.bing.jh.entity.dto.TZwArchivesDto;
import com.bing.jh.entity.vo.AreaVO;
import com.bing.jh.entity.vo.DzWzContrastVO;
import com.bing.jh.service.DzWzInstallMaintenanceStatService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;


/**
 * 装维人员四象限分析-装维成本
 */
@RestController
@RequestMapping("dzWzInstallMaintenanceStat")
public class DzWzInstallMaintenanceStatController {

    @Resource
    private DzWzInstallMaintenanceStatService dzWzInstallMaintenanceStatService;


    @PostMapping("/histogramInstall")
    public BaseResult<List<DzWzContrastVO>> histogramInstall(@RequestBody TZwArchivesDto tZwArchives) {
        List<DzWzContrastVO> list = dzWzInstallMaintenanceStatService.contrast(tZwArchives);
        if (CharSequenceUtil.isEmpty(tZwArchives.getCityCode())){
            List<String> areaVOS = dzWzInstallMaintenanceStatService.queryArea(tZwArchives)
                    .stream()
                    .map(AreaVO::getNewZwName)
                    .collect(Collectors.toList());
            Set<String> existingAreaTypes = list.stream()
                    .map(DzWzContrastVO::getAreaType)
                    .collect(Collectors.toSet());

            //拼装数值为空的地域
            areaVOS.stream()
                    .filter(area -> !existingAreaTypes.contains(area))
                    .forEach(area -> {
                        DzWzContrastVO newVO = new DzWzContrastVO();
                        newVO.setAreaType(area);
                        list.add(newVO);
                    });
        }
        return new BaseResult<>(list);
    }
}
